<?php
/**
 * 开启事务
 * @return [type] [description]
 */
function begin()
{
    M('')->startTrans();
}

/**
 * 开启事务提交
 * @return [type] [description]
 */
function commit()
{
    M('')->commit();
}

/**
 * 事务回滚
 * @return [type] [description]
 */
function rollback()
{
    M('')->rollback();
}

/**
 * 获取最新的sql
 * @return [type] [description]
 */
function last_sql()
{
    var_dump(M('')->getLastSql());
}

/**
 * [table description]
 * @param  string $table_name [description]
 * @return [type]             [description]
 */
function table($table_name = '')
{
    return C('DB_PREFIX') . $table_name;
}

/**
 * 获取用户使用的浏览器类型
 * @param  [type] $glue [description]
 * @return [type]       [description]
 */
function get_client_browser($glue = null)
{
    $browser = array();
    $agent   = $_SERVER['HTTP_USER_AGENT']; //获取客户端信息

    /* 定义浏览器特性正则表达式 */
    $regex = array(
        'ie'      => '/(MSIE) (\d+\.\d)/',
        'chrome'  => '/(Chrome)\/(\d+\.\d+)/',
        'firefox' => '/(Firefox)\/(\d+\.\d+)/',
        'opera'   => '/(Opera)\/(\d+\.\d+)/',
        'safari'  => '/Version\/(\d+\.\d+\.\d) (Safari)/',
    );
    foreach ($regex as $type => $reg) {
        preg_match($reg, $agent, $data);
        if (!empty($data) && is_array($data)) {
            $browser = $type === 'safari' ? array($data[2], $data[1]) : array($data[1], $data[2]);
            break;
        }
    }
    return empty($browser) ? false : (is_null($glue) ? $browser : implode($glue, $browser));
}

/**
 * 获取浏览器agent
 * @return [type] [description]
 */
function get_client_agent()
{
    return $_SERVER['HTTP_USER_AGENT'];
}

/**
 * 获取访问域名
 * @return [type] [description]
 */
function get_domain()
{
    $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
    return $http_type . $_SERVER['HTTP_HOST'];
}

/**
 * 获取ip详细信息
 * @param  [type] $ip [description]
 * @return [type]     [description]
 */
function get_ip_info($ip)
{
    // 有需要可更换ip地址库
    $ip_location = new \Org\Net\IpLocation('UTFWry.dat');
    return $ip_location->getlocation($ip);
}

/**
 * ajax 返回
 * @param  array  $data [description]
 * @return [type]       [description]
 */
function success($data = '')
{
    $data       = $data != null ? $data : [];
    $returnData = [
        'code' => 0,
        'msg'  => 'SUCCESS',
        'data' => $data,
    ];

    ajax_return($returnData);
}

/**
 * ajax返回
 * @param  integer $code [description]
 * @param  string  $msg  [description]
 * @return [type]        [description]
 */
function error($code = 0, $msg = '')
{
    $returnData = [
        'code' => intval($code),
        'msg'  => $msg,
        'data' => [],
    ];

    ajax_return($returnData);
}

/**
 * ajax 返回
 * @param  [type]  $returnData [description]
 * @param  boolean $force      [description]
 * @return [type]              [description]
 */
function ajax_return($returnData)
{
    if (!is_array($returnData)) {
        return false;
    }

    header('Content-Type:application/json; charset=utf-8');
    exit(json_encode($returnData));
}

/**
 * 获取/设置 表键值
 * @param  [type]  $key     [description]
 * @param  string  $value   [description]
 * @param  boolean $refresh [description]
 * @return [type]           [description]
 */
function setting($key, $value = '', $refresh = true)
{
    if ($value) {
        D('Common/setting', 'Service')->set($key, $value, $refresh);
    } else {
        return D('Common/setting', 'Service')->get($key);
    }
}

/**
 * 清空缓存
 * @return [type] [description]
 */
function setting_clean()
{
    return D('Common/setting', 'Service')->clean();
}

/**
 * 获取调用模块下的配置文件内容，默认.php
 * @param  string $file_name [description]
 * @param  string $ext       [description]
 * @return [type]            [description]
 */
function get_conf($file_name = '', $ext = '.php')
{
    $file_path = WEB_PATH . "/Application/" . MODULE_NAME . '/Conf/' . $file_name . $ext;

    if (file_exists($file_path)) {
        return include $file_path;
    } else {
        return null;
    }
}

/**
 * 加密
 * @param  string $string          [加密字符串]
 * @param  string $data_crypt_type [加密方式（Thhink,Base64,Crypt,Des,Xxtea）]
 * @return [type]                  [description]
 */
function encrypt($string = '', $data_crypt_type = 'Think')
{
    $crypt = new \Think\Crypt();
    return $crypt->encrypt($string, C('ENCRYPT_KEY'));
}

/**
 * 解密
 * @param  string $string          [解密字符串]
 * @param  string $data_crypt_type [解密方式（Thhink,Base64,Crypt,Des,Xxtea），请跟加密方式一致]
 * @return [type]                  [description]
 */
function decrypt($string = '', $data_crypt_type = 'Think')
{
    $crypt = new \Think\Crypt();
    return $crypt->decrypt($string, C('ENCRYPT_KEY'));
}

/**
 * 判断是否是手机端
 * @return [type] [description]
 */
function is_mobile()
{
    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
    if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
        return true;
    }

    //此条摘自TPM智能切换模板引擎，适合TPM开发
    if (isset($_SERVER['HTTP_CLIENT']) && 'PhoneClient' == $_SERVER['HTTP_CLIENT']) {
        return true;
    }

    //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset($_SERVER['HTTP_VIA']))
    //找不到为flase,否则为true
    {
        return stristr($_SERVER['HTTP_VIA'], 'wap') ? true : false;
    }

    //判断手机发送的客户端标志,兼容性有待提高
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array(
            'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile',
        );
        //从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return true;
        }
    }
    //协议法，因为有可能不准确，放到最后判断
    if (isset($_SERVER['HTTP_ACCEPT'])) {
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
            return true;
        }
    }
    return false;
}

/**
 * 是否utf-8编码
 * @param  string  $string [description]
 * @return boolean         [description]
 */
function is_utf8($string = '')
{
    $string = new \Org\Util\String();
    return $string::isUtf8($string);
}

/**
 * 是否有效的邮箱地址
 * @param  [type]  $email [description]
 * @return boolean        [description]
 */
function is_email($email = '')
{
    if (ereg('^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+', $email)) {
        return true;
    } else {
        return false;
    }
}

/**
 * 是否手机号码
 * @param  string  $phone [description]
 * @return boolean        [description]
 */
function is_phone($phone = '')
{
    if (preg_match("/^1[3|4|5|8]\d{9}$/", $phone)) {
        return true;
    } else {
        return false;
    }
}

/**
 * 是否qq号码
 * @param  string  $qq [description]
 * @return boolean     [description]
 */
function is_qq($qq = '')
{
    if (preg_match("/^[1-9]\d{4,10}$/i", $qq)) {
        return true;
    } else {
        return false;
    }
}

/**
 * 是否数字
 * @param  integer $number [description]
 * @return boolean         [description]
 */
function is_number($number = 0)
{
    if (ereg("^[0-9]+$", $number)) {
        return true;
    } else {
        return false;
    }
}

/**
 * 是否邮编
 * @param  string  $postcode [description]
 * @return boolean           [description]
 */
function is_postcode($postcode = '')
{
    if (ereg("^[0-9]{4,6}$", $val)) {
        return true;
    } else {
        return false;
    }
}

/**
 * 是否是英文
 * @param  string  $english [description]
 * @return boolean          [description]
 */
function is_english($english = '')
{
    if (ereg("[\x80-\xff].", $english)) {
        return false;
    } else {
        return true;
    }

}

/**
 * 是否ip地址
 * @param  [type]  $ip [description]
 * @return boolean     [description]
 */
function is_ip($ip)
{
    return (bool) ip2long($ip);
}

/**
 * 是否有效域名
 * @param  string  $domain [description]
 * @return boolean         [description]
 */
function is_domain($domain = '')
{
    if (!eregi("^[0-9a-z]+[0-9a-z\.-]+[0-9a-z]+$", $domain)) {
        return false;
    }
    if (!eregi("\.", $domain)) {
        return false;
    }

    if (eregi("\-\.", $domain) or eregi("\-\-", $domain) or eregi("\.\.", $domain) or eregi("\.\-", $domain)) {
        return false;
    }

    $adomain = explode(".", $domain);
    if (!eregi("[a-zA-Z]", $adomain[count($adomain) - 1])) {
        return false;
    }

    if (strlen($adomain[0]) > 63 || strlen($adomain[0]) < 1) {
        return false;
    }

    return true;
}

/**
 * 判断是否有效的url
 * @param  [type]  $url [description]
 * @return boolean      [description]
 */
function is_url($url)
{
    if (!preg_match('/http:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is', $url)) {
        return false;
    } else {
        return true;
    }
}

/**
 * 判断是否中文
 * @param  [type]  $str [description]
 * @return boolean      [description]
 */
function is_chinese($str)
{
    if (!eregi("[^\x80-\xff]", "$str")) {
        return true;
    } else {
        return false;
    }
}

/**
 * 判断是否日期格式
 * @param  [type]  $date    [description]
 * @param  array   $formats [description]
 * @return boolean          [description]
 */
function is_date($date, $formats = array("Y-m-d", "Y/m/d"))
{
    $unixTime = strtotime($date);
    if (!$unixTime) {
        //strtotime转换不对，日期格式显然不对。
        return false;
    }
    //校验日期的有效性，只要满足其中一个格式就OK
    foreach ($formats as $format) {
        if (date($format, $unixTime) == $date) {
            return true;
        }
    }

    return false;
}

/**
 * 判断今天星期几
 * @param  string $day [description]
 * @return [type]      [description]
 */
function what_day($day = '', $call = '周')
{
    $day  = $day ? date("w", $day) : date("w");
    $week = ["日", "一", "二", "三", "四", "五", "六"];
    return $call . $week[$day];
}

/**
 * 去除空格，回车，换行
 * @param  [type] $str [description]
 * @return [type]      [description]
 */
function trim_space($str)
{
    $search  = [" ", "　", "\n", "\r", "\t"];
    $replace = ["", "", "", "", ""];
    return str_replace($search, $replace, $str);
}

/**
 * 随机字符串
 * @param  string  $length [description]
 * @param  integer $type   [0大小写字母 1数字 2大写字母 3小写字母 4中文 默认（0+1）]
 * @return [type]          [description]
 */
function rand_string($length = '6', $type = '')
{
    $string = new \Org\Util\String();
    return $string::randString($length, $type);
}

/**
 * 随机数字，不足补0
 * @param  [type] $min [description]
 * @param  [type] $max [description]
 * @return [type]      [description]
 */
function rand_number($min, $max)
{
    $string = new \Org\Util\String();
    return $string::randNumber($min, $max);
}

/**
 * 生成验证码
 * @param  string $uuid [验证码场景 change_passworld:修改密码 login:登录 等场景]
 * @return [type]       [description]
 */
function create_verify($uuid = '')
{
    $verify = new \Think\Verify();
    return $verify->entry($uuid);
}

/**
 * 检查验证码
 * @param  [type] $code [description]
 * @param  string $uuid [description]
 * @return [type]       [description]
 */
function check_verify($code, $uuid = '')
{
    $verify = new \Think\Verify();
    return $verify->check($code, $uuid);
}

/**
 * 发送http
 * @param  [type] $code [description]
 * @return [type]       [description]
 */
function send_http_code($code)
{
    $http = new \Org\Net\Http();
    $http::sendHttpStatus($code);
}

/**
 * 下载远程文件到本地
 * @param  string $remote [下载的文件url]
 * @param  string $local  [保存到本地的路径]
 * @return [type]         [description]
 */
function download($remote = '', $local = '')
{
    $http = new \Org\Net\Http();
    $http::curlDownload($remote, $local);
}

/**
 * [curl 请求]
 * @param  [type] $url  [description]
 * @param  array  $conf [description]
 *                      type : get/post 默认get
 * @return [type]       [description]
 */
function curl_request($url, $conf = [])
{
    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

    // 是否浏览器代理信息
    if ($conf['agent']) {
        curl_setopt($curl, CURLOPT_USERAGENT, $conf['agent']);
    }

    // 是否外链
    if ($conf['referer']) {
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
        curl_setopt($curl, CURLOPT_REFERER, $conf['referer']);
    }

    // 是否post
    if ($conf['post']) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($conf['post']));
    }

    // 是否带上cookie
    if ($conf['cookie']) {
        curl_setopt($curl, CURLOPT_COOKIE, $conf['cookie']);
    }

    // 超时
    curl_setopt($curl, CURLOPT_TIMEOUT, isset($conf['timeout']) ? $conf['timeout'] : 5);

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    // curl_setopt($curl, CURLOPT_HEADER, $returnCookie);

    $data = curl_exec($curl);

    if (curl_errno($curl)) {
        return curl_error($curl);
    }

    curl_close($curl);
    if ($conf['return_cookie']) {

        list($header, $body) = explode("\r\n\r\n", $data, 2);
        preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches);
        $info['cookie']  = substr($matches[1][0], 1);
        $info['content'] = $body;
        return $info;

    } else {

        return $data;
    }
}

/**
 * 导出数据到excel
 * @param  [type] $exp_name  [description]
 * @param  [type] $cell_name [description]
 * @param  [type] $exp_data  [description]
 * @return [type]            [description]
 */
function export_excel($file_name, $cell_name, $exp_data)
{
    $xls_title = iconv('utf-8', 'gb2312', $file_name); //文件名称
    $cell_num  = count($cell_name);
    $data_num  = count($exp_data);
    vendor("PHPExcel.PHPExcel");
    $objPHPExcel = new PHPExcel();
    $cellName    = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');

    for ($i = 0; $i < $cell_num; $i++) {
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '1', $cell_name[$i][1]);
    }

    // Miscellaneous glyphs, UTF-8
    for ($i = 0; $i < $data_num; $i++) {
        for ($j = 0; $j < $cell_num; $j++) {
            $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 2), $exp_data[$i][$cell_name[$j][0]]);
        }
    }

    header('pragma:public');
    header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xls_title . '.xls"');
    header("Content-Disposition:attachment;filename=$file_name.xls"); //attachment新窗口打印inline本窗口打印
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
    exit;
}

/**
 * 导出excel
 * @param  string $header [表头]
 * @param  string $data   [数据]
 * @param  string $naem   [导出名称，一般是随机字符串]
 * @return [type]         [description]
 */
function import_excel($header = [], $data = [], $name)
{
    import("Org.Yufan.Excel");

    if (!is_array($header) || !is_array($data)) {
        return false;
    }

    if (empty($name)) {
        return false;
    }

    $row    = array();
    $row[0] = $header;
    $i      = 1;

    foreach ($data as $key => $item) {
        foreach ($key as $k) {
            $row[$i][] = isset($item[$k]) ? $item[$k] : '';
        }

    }

    $xls = new \Excel_XML('UTF-8', false, 'datalist');
    $xls->addArray($row);
    $xls->generateXML($name);
    exit;
}

/**
 * 发送邮件
 * @param  [type] $to      [description]
 * @param  [type] $title   [description]
 * @param  [type] $content [description]
 * @return [type]          [description]
 */
function send_email($to, $title, $content)
{
    Vendor('PHPMailer.PHPMailerAutoload');

    $mail = new PHPMailer(); //实例化

    $mail->IsSMTP(); // 启用SMTP

    $mail->Host     = C('MAIL_HOST'); //smtp服务器的名称
    $mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
    $mail->Username = C('MAIL_USERNAME'); //你的邮箱名
    $mail->Password = C('MAIL_PASSWORD'); //邮箱密码
    $mail->From     = C('MAIL_FROM'); //发件人地址（也就是你的邮箱地址）
    $mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
    $mail->AddAddress($to, "尊敬的客户");
    $mail->WordWrap = 50; //设置每行字符长度
    $mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
    $mail->CharSet = C('MAIL_CHARSET'); //设置邮件编码
    $mail->Subject = $title; //邮件主题
    $mail->Body    = $content; //邮件内容
    $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
    return ($mail->Send());
}

/**
 * 上传文件/图片等
 * @param  string  $path 路径
 * @param  integer $size 大小 默认3145728 ==3M
 * @param  array   $ext  扩展类型，默认 'jpg', 'gif', 'png', 'jpeg'
 * @return [type]        [description]
 */
function upload($path = '', $ext = ['jpg', 'gif', 'png', 'jpeg'], $size = 3145728)
{
    $upload           = new \Think\Upload(); // 实例化上传类
    $upload->maxSize  = $size; // 设置附件上传大小
    $upload->exts     = $ext; // 设置附件上传类型
    $upload->rootPath = './Uploads/'; // 设置附件上传根目录
    $upload->savePath = $path . '/'; // 设置附件上传（子）目录

    $info = $upload->upload();
    if (!$info) {
        return $upload->getError();
    } else {

        foreach ($info as $key => $value) {
            $info[$key]['url'] = '/Uploads/' . $value['savepath'] . $value['savename'];
        }

        return $info;
    }
}

/**
 * 生成二维码
 * @param  [type]  $url
 * @param  integer $size 图片大小
 * @return [type]        [description]
 */
function qrcode($url, $size = 4)
{
    Vendor('Phpqrcode.phpqrcode');
    QRcode::png($url, false, QR_ECLEVEL_L, $size, 2, false, 0xFFFFFF, 0x000000);
}

/**
 * 生成pdf
 * @param  string $html      需要生成的内容
 */
function pdf($file_name = CUR_DATETIME, $html = '<h1 style="color:red">hello word</h1>')
{
    vendor('Tcpdf.tcpdf');
    $pdf = new \Tcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // 设置打印模式
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Nicola Asuni');
    $pdf->SetTitle('TCPDF Example 001');
    $pdf->SetSubject('TCPDF Tutorial');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    // 是否显示页眉
    $pdf->setPrintHeader(false);
    // 设置页眉显示的内容
    $pdf->SetHeaderData('logo.png', 60, '', '', array(0, 64, 255), array(0, 64, 128));
    // 设置页眉字体
    $pdf->setHeaderFont(array('dejavusans', '', '12'));
    // 页眉距离顶部的距离
    $pdf->SetHeaderMargin('5');
    // 是否显示页脚
    $pdf->setPrintFooter(true);
    // 设置页脚显示的内容
    $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
    // 设置页脚的字体
    $pdf->setFooterFont(array('dejavusans', '', '10'));
    // 设置页脚距离底部的距离
    $pdf->SetFooterMargin('10');
    // 设置默认等宽字体
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // 设置行高
    $pdf->setCellHeightRatio(1);
    // 设置左、上、右的间距
    $pdf->SetMargins('10', '10', '10');
    // 设置是否自动分页  距离底部多少距离时分页
    $pdf->SetAutoPageBreak(true, '15');
    // 设置图像比例因子
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->setFontSubsetting(true);
    $pdf->AddPage();
    // 设置字体
    $pdf->SetFont('stsongstdlight', '', 14, '', true);
    $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
    $pdf->Output($file_name . '.pdf', 'I');
}

/**
 * 系统路径转化为项目路径
 * @param  [type] $path [description]
 * @return [type]       [description]
 */
function systempath2webpath($path)
{
    return str_replace(WEB_PATH, '', $path);
}

/**
 * 获取当前url
 * @return [type] [description]
 */
function get_current_url()
{
    $current_url = 'http://';
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $current_url = 'https://';
    }
    if ($_SERVER['SERVER_PORT'] != '80') {
        $current_url .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
    } else {
        $current_url .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    }
    return $current_url;
}

/**
 * 获取请求头
 */
if (!function_exists('getallheaders')) {
    function getallheaders()
    {
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        return $headers;
    }
}
